import { Get, Inject, Injectable, Logger, OnModuleInit, Post, } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import databaseConfig from 'src/config/database.config';
import { ConfigType } from '@nestjs/config';
import { AuthService } from 'src/auth/auth.service';

import { EventEmitter2 } from '@nestjs/event-emitter';


@Injectable()
// Bug 修复：将 OnMoudelInit 修改为 OnModuleInit
export class UserService implements OnModuleInit {
    // constructor(private configService: ConfigService) {
    //   const host = this.configService.get('database.host');

    //   console.log('databasehost11', host);
    // }

    // constructor(
    //   @Inject(databaseConfig.KEY)
    //   private dbConfig: ConfigType<typeof databaseConfig>,
    //   @Inject('VALUE_PROVIDER') private valueProvider: string,
    //   @Inject('CLASS_PROVIDER') private classProvider: AuthService,
    // ) {

    //   console.log('databasehost22', typeof databaseConfig);
    //   console.log('valueProvider', this.valueProvider);

    // }

    // 创建日志器
    private readonly logger = new Logger(UserService.name);

    constructor(
        @Inject('FACTORY_PROVIDER')
        private factoryProvider: Record<string, number>,
        private eventEmitter: EventEmitter2,
    ) {
        console.log('factoryProvider', this.factoryProvider.age);
    }

    async create(user) {
        this.logger.log('create user', user);

        this.eventEmitter.emit('user.create', user);

        return user;
    }

    async onModuleInit() {}

}
